package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.AttendanceDedParamAddDTO;
import org.jsola.hr.dto.AttendanceDedParamUpdateDTO;
import org.jsola.hr.entity.AttendanceDedParamDO;
import org.jsola.hr.query.AttendanceDedParamQuery;
import org.jsola.hr.service.IAttendanceDedParamService;
import org.jsola.hr.vo.AttendanceDedParamVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * @author zhr
 */
@Component
public class AttendanceDedParamTestHelper extends BaseTestHelper {
    
    @Autowired
    private IAttendanceDedParamService attendanceDedParamService;

    /**
     * 生成add测试数据
     * @return AttendanceDedParamAddDTO
     */
    public AttendanceDedParamAddDTO getAttendanceDedParamAddDTO(){
        AttendanceDedParamAddDTO attendanceDedParamAddDTO = new AttendanceDedParamAddDTO();
        attendanceDedParamAddDTO.setItemId(getRandomValue("varchar",32));
        attendanceDedParamAddDTO.setTimesOperator(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendanceDedParamAddDTO.setTimesValue(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceDedParamAddDTO.setDedType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendanceDedParamAddDTO.setDedAmount(SafeKit.getInteger(getRandomValue("int",11)));
        attendanceDedParamAddDTO.setAbsenteeismType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        attendanceDedParamAddDTO.setAbsenteeismValue(SafeKit.getBigDecimal(getRandomValue("decimal",11)));
        attendanceDedParamAddDTO.setCompanyId(getRandomValue("varchar",32));
        return attendanceDedParamAddDTO;
    }


    /**
     * 生成update测试数据
     * @return AttendanceDedParamUpdateDTO
     */
    public AttendanceDedParamUpdateDTO getAttendanceDedParamUpdateDTO(AttendanceDedParamVO attendanceDedParamVO){
        return attendanceDedParamService.selectDOById(attendanceDedParamVO.getId(), SITE_ID).to(AttendanceDedParamUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return AttendanceDedParamQuery
     */
    public AttendanceDedParamQuery getAttendanceDedParamQuery() {
        AttendanceDedParamQuery attendanceDedParamQuery = new AttendanceDedParamQuery();
        List<AttendanceDedParamDO> attendanceDedParamDOList = attendanceDedParamService.list(new AttendanceDedParamDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(attendanceDedParamDOList)) {
            AttendanceDedParamDO attendanceDedParamDO = attendanceDedParamDOList.get(0);
            attendanceDedParamQuery = attendanceDedParamDO.to(AttendanceDedParamQuery.class);
            if (attendanceDedParamDO.getAbsenteeismValue() != null) {
                attendanceDedParamQuery.setAbsenteeismValueStart(attendanceDedParamDO.getAbsenteeismValue().subtract(new BigDecimal(1)));
                attendanceDedParamQuery.setAbsenteeismValueEnd(attendanceDedParamDO.getAbsenteeismValue().add(new BigDecimal(1)));
            }
            if (attendanceDedParamDO.getGmtCreate() != null) {
                attendanceDedParamQuery.setGmtCreateStart(DateKit.getBeforeDay(attendanceDedParamDO.getGmtCreate(),-1));
                attendanceDedParamQuery.setGmtCreateEnd(DateKit.getBeforeDay(attendanceDedParamDO.getGmtCreate(),1));
            }
            if (attendanceDedParamDO.getGmtModified() != null) {
                attendanceDedParamQuery.setGmtModifiedStart(DateKit.getBeforeDay(attendanceDedParamDO.getGmtModified(),-1));
                attendanceDedParamQuery.setGmtModifiedEnd(DateKit.getBeforeDay(attendanceDedParamDO.getGmtModified(),1));
            }
        }
        return attendanceDedParamQuery;
    }

    /**
     * 保存示例
     * @return AttendanceDedParamVO
     */
    public AttendanceDedParamVO saveAttendanceDedParamExample(){
        AttendanceDedParamAddDTO addDTO = this.getAttendanceDedParamAddDTO();
        AttendanceDedParamVO attendanceDedParamVO = attendanceDedParamService.save(addDTO,buildTokenUser());
        return attendanceDedParamVO;
    }


}

